
/* Generated by Interface Builder */

#import "MyView.h"
#import "tree.h"
#import <appkit/Control.h>
#import <appkit/Application.h>
#include <appkit/Pasteboard.h>
#import <dpsclient/wraps.h>


@implementation MyView

+newFrame:(const NXRect *)tF {
    self = [super newFrame:tF];
    branchChange = .7;
    widthChange = .7;
    moveLeft = 0.0;
    height = 1.0;
    branchLength = 200.0;
    rightBranch = 50.0;
    leftBranch = -30.0;
    lineWidth = 40.0;
    moveRight = 200.0;
    width = .8;
// same !!
    maxDepth = 9.0;
    moveLeft = 6.0;
}

- branchChange:sender
{
   branchChange = [sender floatValue];
   [self display];
   return self;
}

- widthChange:sender
{
    widthChange = [sender floatValue];
    [self display];
    return self;
}

- moveLeft:sender
{
    moveLeft = [sender floatValue];
   [self display];
    return self;
}

- height:sender
{
    height = [sender floatValue];
    [self display];
    return self;
}

- branchLength:sender
{
    branchLength = [sender floatValue];
    [self display];
    return self;
}

- rightBranch:sender
{
    rightBranch = [sender floatValue];
    [self display];
    return self;
}

- leftBranch:sender
{
    leftBranch = [sender floatValue];
    [self display];
    return self;
}

- lineWidth:sender
{
    lineWidth = [sender floatValue];
    [self display];
    return self;
}

- moveRight:sender
{
    moveRight = [sender floatValue];
    [self display];
    return self;
}

- width:sender
{
    width = [sender floatValue];
    [self display];
    return self;
}

- copy:sender { 
   id pb = [NXApp pasteboard];  /* global Pasteboard object */ 
   NXStream  *st;               /* stream to collect data in */ 
   char      *data;             /* actual data buffer */ 
   int       length;            /* length of data */ 
   int       maxLength;         /* (not used here) */

   // To see how to use the pasteboard see page 10-33 of
   // the SysRefMan
   // declare that we will supply a single type of data: PostScript
   [pb declareTypes:&NXPostScriptPboard num:1 owner:self];

   /* get a stream which writes to memory */ 
   st = NXOpenMemory( NULL, 0, NX_WRITEONLY );

   /* write PostScript code for this view into the stream */ 
   [self copyPSCodeInside:NULL to:st];

   /* get actual data buffer from stream */ 
   NXGetMemoryBuffer( st, &data, &length, &maxLength );

   /* write PostScript data to pasteboard */ 
   [pb writeType:NXPostScriptPboard data:data length:length];

   /* deallocate stream, including its buffer */ 
   NXCloseMemory( st, NX_FREEBUFFER );

   return self; 
}

/* make this view accept first responder so it will understand copy */
-(BOOL)acceptsFirstResponder
{
	return (YES);
}

-resignFirstResponder
{
	return self;
}


- drawSelf:(NXRect*)r :(int)c
{
    NXEraseRect(&bounds);
    PSsetgray(NX_BLACK);
    PSsetlinewidth(lineWidth);
    doTree(moveLeft, leftBranch, rightBranch, branchLength, moveRight, width, height, lineWidth, branchChange, widthChange);
    return self;
}


@end
